/*
 * GeekOS - x86 timer device
 *
 * Copyright (C) 2001-2008, David H. Hovemeyer <david.hovemeyer@gmail.com>
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *   
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *  
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <geekos/timer.h>
#include <geekos/irq.h>
#include <geekos/cons.h>

#define TIMER_IRQ 0

static void timer_int_handler(struct thread_context *context)
{
	irq_begin(context);
	timer_process_tick();
	irq_end(context);
}

void timer_init(void)
{
	cons_printf("Timer initialized\n");
	/*
	 * FIXME: for now, just leave the default 18Hz periodic timer.
	 */
	irq_install_handler(TIMER_IRQ, &timer_int_handler);
	irq_enable(TIMER_IRQ);

	/* now that we have a timer interrupt handler installed, we can
	 * enable interrupt handling and preemption */
	int_enable();
	g_preemption = true;
}
